package cn.hnbjx.prepaid.service;

import cn.hnbjx.prepaid.dao.AccountDao;
import cn.hnbjx.prepaid.dao.RescueUserDao;
import cn.hnbjx.prepaid.dao.UserHelpDao;
import cn.hnbjx.prepaid.pojo.Account;
import cn.hnbjx.prepaid.pojo.NumData;
import cn.hnbjx.prepaid.pojo.RescueUser;
import cn.hnbjx.prepaid.pojo.UserHelp;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class RescueUserService {
    @Autowired
    private RescueUserDao rescueUserDao;
    @Autowired
    private AccountDao accountDao;
    @Autowired
    private UserHelpDao userHelpDao;

    public PageInfo<RescueUser> findAll(int page, String key) {
        PageHelper.startPage(page,10);
        List<RescueUser> rescueUsers = rescueUserDao.findAll(key);
        for (RescueUser rescueUser : rescueUsers) {
            Account account = accountDao.findById(rescueUser.getRescueUserId());
            rescueUser.setRescueUser(account);
            Account account1 = accountDao.findById(rescueUser.getUserId());
            rescueUser.setUser(account1);
            UserHelp userHelp1 = userHelpDao.findById(rescueUser.getUserHelpId());
            rescueUser.setUserHelp(userHelp1);
        }
        PageInfo<RescueUser> rescueUsersPageInfo = new PageInfo<>(rescueUsers);
        return rescueUsersPageInfo;
    }
    public PageInfo<RescueUser> apifindAll(int page, int type,int id) {
        PageHelper.startPage(page,10);
        List<RescueUser> rescueUsers = rescueUserDao.apifindAll(type,id);
        for (RescueUser rescueUser : rescueUsers) {
            Account account = accountDao.findById(rescueUser.getRescueUserId());
            rescueUser.setRescueUser(account);
            Account account1 = accountDao.findById(rescueUser.getUserId());
            rescueUser.setUser(account1);
            UserHelp userHelp1 = userHelpDao.findById(rescueUser.getUserHelpId());
            rescueUser.setUserHelp(userHelp1);
        }
        PageInfo<RescueUser> rescueUsersPageInfo = new PageInfo<>(rescueUsers);
        return rescueUsersPageInfo;
    }
    public void  insert(RescueUser rescueUser){
        rescueUserDao.insert(rescueUser);
        return;
    }
    public  List<NumData> findByNum(){
        return  rescueUserDao.findByNum();
    }
}
